//
//  HomeViewController.m
//  ZmlMagicTour
//
//  Created by 张明磊 on 14-4-3.
//  Copyright (c) 2014年 张明磊. All rights reserved.
//

#import "HomeViewController.h"
#import "RESideMenu.h"

@interface HomeViewController ()

@property (strong, nonatomic) RESideMenu *sideMenu;

@end

@implementation HomeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self installTitleView_home];
    
	// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)installTitleView_home
{
    UIView *view_title = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
    view_title.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:view_title];
    IOS7(view_title);
    
    UIButton *button_menu = [UIButton buttonWithType:UIButtonTypeCustom];
    button_menu.frame = CGRectMake(15, view_title.frame.size.height - 35, 50, 30);
    button_menu.backgroundColor = [UIColor clearColor];
    [button_menu setTitle:NSLocalizedString(@"menu", nil) forState:UIControlStateNormal];
    [button_menu setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button_menu addTarget:self action:@selector(didClickButton_menu:) forControlEvents:UIControlEventTouchUpInside];
    [view_title addSubview:button_menu];
    button_menu.layer.cornerRadius = 3.0;
}


- (void)didClickButton_menu:(UIButton *)button_menu
{
    if(!_sideMenu)
    {
        RESideMenuItem *homeItem = [[RESideMenuItem alloc] initWithTitle:@"相册" action:^(RESideMenu *menu, RESideMenuItem *item) {
            //[_sideMenu hide];
            //DemoViewController *viewController = [[DemoViewController alloc] init];
            //viewController.title = item.title;
            //UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
            //[menu setRootViewController:navigationController];
        }];
        
        RESideMenu *sideMenu = [[RESideMenu alloc] initWithItems:@[homeItem]];
        _sideMenu = sideMenu;
        if(iPhone5)
        {
            sideMenu.verticalOffset = 110;
        }
        else
        {
            sideMenu.verticalOffset = 76;
        }
        sideMenu.hideStatusBarArea = !IOS7_VERSION;
    }
    [_sideMenu show];
}

@end
